package com.bai.process.service.impl;


import com.bai.model.process.ProcessTemplate;
import com.bai.model.process.ProcessType;
import com.bai.process.mapper.OaProcessTypeMapper;
import com.bai.process.service.OaProcessTemplateService;
import com.bai.process.service.OaProcessTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author bai
 * @since 2023-05-27
 */
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType> implements OaProcessTypeService {

    @Autowired
    private OaProcessTemplateService processTemplateService;

    /**
     * 查询所有审批分类和每个分类所有审批模板
     *
     * @return
     */
    @Override
    public List<ProcessType> findProcessType() {
        //TODO:查询所有的审批分类，返回list集合
        List<ProcessType> processTypeList = baseMapper.selectList(null);
        //TODO:遍历所有的审批集合
        for (ProcessType processType : processTypeList) {
            //TODO:根据审批分类的集合的id查询所有模板
            //审批分类id
            Long id = processType.getId();
            LambdaQueryWrapper<ProcessTemplate> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ProcessTemplate::getProcessTypeId, id);
            List<ProcessTemplate> list = processTemplateService.list(queryWrapper);
            //TODO:根据审批分类id查询对应审批模板数据封装
            processType.setProcessTemplateList(list);
        }
        return processTypeList;
    }
}
